#!/bin/bash
systemFileName="./docker-compose-system-i.yml"
encipherFileName="./docker-compose-encipher-i.yml"
cdate=$(date +%Y%m%d)
if [ -e "$systemFileName" ]; then
  echo "i机system文件"
  # 移动 docker-compose-system-i.yml 文件到 /app/pmapp/scripts/privacy/system/文件夹下
  # 判断 docker-compose-system-i.yml 是否存在
  if [ -e "/app/pmapp/scripts/privacy/system/docker-compose-system.yml" ]; then
    echo "停止system服务"
    docker-compose -f /app/pmapp/scripts/privacy/system/docker-compose-system.yml down
    # 备份 docker-compose-system-i.yml 文件夹
    echo "备份docker-compose-system.yml文件"
    mv /app/pmapp/scripts/privacy/system/docker-compose-system.yml /app/pmapp/bak/service/$cdate/
  fi
  echo "修改docker-compose-system-i.yml文件名称"
  cp ./docker-compose-system-i.yml /app/pmapp/scripts/privacy/system/
  mv /app/pmapp/scripts/privacy/system/docker-compose-system-i.yml /app/pmapp/scripts/privacy/system/docker-compose-system.yml
  echo "启动system服务"
  docker-compose -f /app/pmapp/scripts/privacy/system/docker-compose-system.yml up -d
fi


if [ -e "$encipherFileName" ]; then
  echo "i机encipher文件"
  # 移动 docker-compose-encipher-i.yml 文件到 /app/pmapp/scripts/privacy/encipher/文件夹下
  # 判断 docker-compose-encipher-i.yml 是否存在
  if [ -e "/app/pmapp/scripts/privacy/encipher/docker-compose-encipher.yml" ]; then
    echo "停止encipher服务"
    docker-compose -f /app/pmapp/scripts/privacy/encipher/docker-compose-encipher.yml down
    # 备份 docker-compose-encipher-i.yml 文件夹
    echo "备份docker-compose-encipher.yml文件"
    mv /app/pmapp/scripts/privacy/encipher/docker-compose-encipher.yml /app/pmapp/bak/service/$cdate/
  fi
  echo "修改docker-compose-encipher-i.yml文件名称"
  cp ./docker-compose-encipher-i.yml /app/pmapp/scripts/privacy/encipher/
  mv /app/pmapp/scripts/privacy/encipher/docker-compose-encipher-i.yml /app/pmapp/scripts/privacy/encipher/docker-compose-encipher.yml
  echo "启动encipher服务"
  docker-compose -f /app/pmapp/scripts/privacy/encipher/docker-compose-encipher.yml up -d
fi
